//==============================================================================
//
//               Copyright (C) 2003  Dick van Oudheusden
//  
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
//==============================================================================
// 
//  $Date: 2003-11-30 19:11:27 $ $Revision: 1.1 $
//
//==============================================================================

#include <stdlib.h>

#include "ofc/config.h"

#include "ofc/DRnd.h"

#include "DInc.h"
#include "DTest.h"

//-Misc------------------------------------------------------------------------

void DRnd_test()
{
  DRnd       *rnd       = [DRnd alloc];
  int         cnt;
  
  STARTTEST();

  [rnd init :2];

  TEST([rnd nextInt] == -1117695901);
  TEST([rnd nextInt] == 421659426);
  TEST([rnd nextInt] == -780014829);
  TEST([rnd nextInt] == 1542679594);
  TEST([rnd nextInt] == 1332541983);
  TEST([rnd nextInt] == 923186428);
  TEST([rnd nextInt] == -3055942);
  TEST([rnd nextInt] == 1225122039);
  TEST([rnd nextInt] == 1444222912);
  TEST([rnd nextInt] == 1353324448);
  TEST([rnd nextInt] == 912560496);
  TEST([rnd nextInt] == -1595695320);
  TEST([rnd nextInt] == -1745516996);
  TEST([rnd nextInt] == -749677414);
  TEST([rnd nextInt] == -1652151353);
  TEST([rnd nextInt] == -1392767240);
  TEST([rnd nextInt] == 923772148);
  TEST([rnd nextInt] == -377060050);
  TEST([rnd nextInt] == -494342043);
  TEST([rnd nextInt] == 111985541);
  TEST([rnd nextInt] == -332982731);
  TEST([rnd nextInt] == 177312573);
  TEST([rnd nextInt] == 867565641);
  TEST([rnd nextInt] == 1880159771);
  TEST([rnd nextInt] == -380023242);
  TEST([rnd nextInt] == 1396182897);
  TEST([rnd nextInt] == -47635369);
  TEST([rnd nextInt] == -518152496);
  TEST([rnd nextInt] == -2039302856);
  TEST([rnd nextInt] == 1822083668);
  TEST([rnd nextInt] == -2039136450);
  TEST([rnd nextInt] == 801925757);
  TEST([rnd nextInt] == 2144902953);
  TEST([rnd nextInt] == 1527098987);
  TEST([rnd nextInt] == -2019593810);
  TEST([rnd nextInt] == -410080475);
  TEST([rnd nextInt] == -1512677467);
  TEST([rnd nextLong] == 388482661);
  TEST([rnd nextInt] == 265495685);
  TEST([rnd nextInt] == -1866803275);
  TEST([rnd nextInt] == 1545567613);
  TEST([rnd nextInt] == -1503605847);
  TEST([rnd nextInt] == -1014085333);
  TEST([rnd nextInt] == 1201102286);
  TEST([rnd nextInt] == 1324602197);
  TEST([rnd nextInt] == -951769875);
  TEST([rnd nextInt] == 1359621073);
  TEST([rnd nextInt] == 904437991);
  TEST([rnd nextInt] == -2031962968);
  TEST([rnd nextLong] == -1092342148);

  for (cnt = 0; cnt < 50; cnt++)
  {
    int r = [rnd nextInt :10 :30];
    
    TEST((r >= 10) && (r <= 30));
  }

#if 0
  for (cnt = 0; cnt < 50; cnt++)
    printf("%g,", [rnd nextDouble]);
  
  printf("\n");
#endif
  
  for (cnt = 0; cnt  < 50; cnt++)
  {
    double r = [rnd nextDouble :12.4 :12.5];
    
    TEST((r >= 12.4) && (r < 12.5));
  }

  [rnd free];
  
  STOPTEST();
}

